const screenresultservice = require("../../apiservice/screen/screenresultservice.js");
const leadservice = require("../../apiservice/lead/leadservice.js");

//创建结果列表
function createScreenResults(resultList, funName) {
	wx.showLoading({
		title: '提交中...',
		mask: true
	})
	screenresultservice.CreateScreenResults (resultList).then(function (res) {
		console.log(res);
		wx.hideLoading();	
		if (res.data.resultState == 1) {
			wx.showToast({
				title: '添加成功',
				icon: 'success',
				duration: 2000
			});
			if (typeof funName === "function") {
				funName(res.data);
			}
			wx.navigateBack({
				delta:1
			})
		} else if (res.data.resultState == 0) {
			wx.showToast({
				title: '添加失败',
				icon: 'none',
				duration: 2000
			});
		}

	}).catch(function (ex) {
		console.log(ex);
		wx.hideLoading();
		wx.showToast({
			title: '添加失败',
			icon: 'none',
			duration: 2000
		});
	})
};

//更新结果集
function updateScreenResults(resultList) {
	wx.showLoading({
		title: '提交中...',
		mask: true
	})
	screenresultservice.UpdateScreenResults(resultList).then(function (res) {
		console.log(res);
		wx.hideLoading();
		if (res.data.resultState == 1) {
			wx.showToast({
				title: '修改成功',
				icon: 'success',
				duration: 2000
			});
			wx.navigateBack({
				delta:1
			})
		} else if (res.data.resultState == 0) {
			wx.showToast({
				title: '修改失败',
				icon: 'none',
				duration: 2000
			});
		}

	}).catch(function (ex) {
		console.log(ex);
		wx.hideLoading();
		wx.showToast({
			title: '添加失败',
			icon: 'none',
			duration: 2000
		});
	})
};
//获取潜客信息
async function  getLeadInfo (leadid){
		var result = await leadservice.QueryLeadInfoById(leadid);
		console.log(result);
		return result.data;
};

//创建结果列表
function createScreenResultsSchool(obj, funName) {
	wx.showLoading({
		title: '提交中...',
		mask: true
	})
	screenresultservice.PostBatchScreenResult (obj).then(function (res) {
		console.log(res);
		wx.hideLoading();	
		if (res.data.resultState == 1) {
			wx.showToast({
				title: '添加成功',
				icon: 'success',
				duration: 2000
			});
			if (typeof funName === "function") {
				funName(res.data);
			}
			wx.navigateBack({
				delta:1
			})
		} else if (res.data.resultState == 0) {
			wx.showToast({
				title: '添加失败',
				icon: 'none',
				duration: 2000
			});
		}

	}).catch(function (ex) {
		console.log(ex);
		wx.hideLoading();
		wx.showToast({
			title: '添加失败',
			icon: 'none',
			duration: 2000
		});
	})
};


module.exports = {
	createScreenResults,
	updateScreenResults,
	getLeadInfo,
	createScreenResultsSchool
}
